﻿
CREATE Function dbo.f_LastLastDate
(@LoanID int = 235728,@Pulled bit = 1 )
RETURNS int WITH SCHEMABINDING BEGIN

DECLARE @Ret int

IF @Pulled <> 1 RETURN dbo.RegistryValue('DefaultRuleValue')

SELECT @Ret = MIN(DATEDIFF(mm,LastDate,DatePulled))
FROM dbo.v_TradeReferences
WHERE LoanID = @LoanID

RETURN  @Ret
END






